package cn.tedu.logistics.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tedu.logistics.bean.Car;
import cn.tedu.logistics.dao.CarDao;
import cn.tedu.logistics.utils.BeanValidate;

@Service
public class CarServiceImpl implements CarService {
	@Autowired
	private CarDao carDao;

	public List<Car> findCar() {
		List<Car> list = carDao.selectList(null);
		return list;
	}

	public void addCar(Car car) {
		String name = car.getCarId();
//		if (BeanValidate.checkNull(car)) {
//			System.out.println("存在空值");
//			return;
//		}
		carDao.insert(car);
	}

	public void delCar(String carId) {
		carDao.deleteById(carId);
	}

	public Car selectById(String carId) {
		return carDao.selectById(carId);
	}

	public void updateCar(Car car) {
//		if (BeanValidate.checkNull(car)) {
//			System.out.println("存在空值");
//			return;
//		}
		carDao.updateById(car);
	}

	public int checkCar(String carId) {//校验部分尚未完成
		int result=0;
		List<Car> list = carDao.selectList(null);
		for(Car c:list) {
			String id = c.getCarId();
			if(carId.equals(id)) {
				result=1;
				break;
			}
		}
		return result;
	}
}
